package com.zff.rental.controller.apartment;


import com.zff.rental.AppConstant;
import com.zff.rental.common.PageVo;
import com.zff.rental.common.Result;
import com.zff.rental.service.apartment.ApartmentPermissionServer;
import com.zff.rental.service.apartment.RoomServer;
import com.zff.rental.vo.apartment.room.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 房间管理
 *
 * @author HCY
 */
@RestController
@RequestMapping(AppConstant.RM_ROOM_MANAGE)
public class RoomManageController {
    @Resource
    private RoomServer roomServer;
    @Resource
    private ApartmentPermissionServer apartmentPermissionServer;

    /**
     * 添加房间
     */
    @PostMapping("/add")
    public Result<RoomVo> add(@Validated @RequestBody AddRoomParams params) {
        apartmentPermissionServer.checkPermission(params.getApartmentId());

        RoomVo result = roomServer.add(params);
        return Result.success(result);
    }

    /**
     * 批量添加房间
     */
    @PostMapping("/batchAdd")
    public Result<Boolean> batchAdd(@Validated @RequestBody BatchAddRoomParams params) {
        apartmentPermissionServer.checkPermission(params.getApartmentId());

        Boolean result = roomServer.batchAdd(params);
        return Result.success(result);
    }

    /**
     * 批量修改房间信息
     */
    @PostMapping("/batchModify")
    public Result<Boolean> batchModify(@Validated @RequestBody BatchModifyRoomParams params) {
        Boolean result = roomServer.batchModify(params);
        return Result.success(result);
    }

    /**
     * 修改房间
     */
    @PostMapping("/modify")
    public Result<RoomVo> modify(@Validated @RequestBody ModifyRoomParams params) {
        RoomVo result = roomServer.modify(params);
        return Result.success(result);
    }

    /**
     * 删除房间
     */
    @GetMapping("/remove")
    public Result<Boolean> remove(@RequestParam("id") Long id) {
        Boolean result = roomServer.remove(id);
        return Result.success(result);
    }

    /**
     * 房间详情
     */
    @GetMapping("/details")
    public Result<RoomVo> details(@RequestParam("id") Long id) {
        RoomVo result = roomServer.details(id);
        return Result.success(result);
    }

    /**
     * 房间列表
     */
    @PostMapping("/list")
    public Result<PageVo<RoomVo>> list(@RequestBody RoomListParams params) {
        PageVo<RoomVo> result = roomServer.list(params);
        return Result.success(result);
    }
}